home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Apache / bin / apxs < prev    next >
Encoding:
Text File  |  2001-06-06  |  21.5 KB  |  708 lines

  1. #!/usr/bin/perl
  2. ## ====================================================================
  3. ## The Apache Software License, Version 1.1
  4. ##
  5. ## Copyright (c) 2000 The Apache Software Foundation.  All rights
  6. ## reserved.
  7. ##
  8. ## Redistribution and use in source and binary forms, with or without
  9. ## modification, are permitted provided that the following conditions
  10. ## are met:
  11. ##
  12. ## 1. Redistributions of source code must retain the above copyright
  13. ##    notice, this list of conditions and the following disclaimer.
  14. ##
  15. ## 2. Redistributions in binary form must reproduce the above copyright
  16. ##    notice, this list of conditions and the following disclaimer in
  17. ##    the documentation and/or other materials provided with the
  18. ##    distribution.
  19. ##
  20. ## 3. The end-user documentation included with the redistribution,
  21. ##    if any, must include the following acknowledgment:
  22. ##       "This product includes software developed by the
  23. ##        Apache Software Foundation (http://www.apache.org/)."
  24. ##    Alternately, this acknowledgment may appear in the software itself,
  25. ##    if and wherever such third-party acknowledgments normally appear.
  26. ##
  27. ## 4. The names "Apache" and "Apache Software Foundation" must
  28. ##    not be used to endorse or promote products derived from this
  29. ##    software without prior written permission. For written
  30. ##    permission, please contact apache@apache.org.
  31. ##
  32. ## 5. Products derived from this software may not be called "Apache",
  33. ##    nor may "Apache" appear in their name, without prior written
  34. ##    permission of the Apache Software Foundation.
  35. ##
  36. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. ## DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. ## SUCH DAMAGE.
  48. ## ====================================================================
  49. ##
  50. ## This software consists of voluntary contributions made by many
  51. ## individuals on behalf of the Apache Software Foundation.  For more
  52. ## information on the Apache Software Foundation, please see
  53. ## <http://www.apache.org/>.
  54. ##
  55. ## Portions of this software are based upon public domain software
  56. ## originally written at the National Center for Supercomputing Applications,
  57. ## University of Illinois, Urbana-Champaign.
  58. ##
  59. ##
  60.  
  61. ##
  62. ##  apxs -- APache eXtenSion tool
  63. ##  Written by Ralf S. Engelschall <rse@apache.org>
  64. ##
  65.  
  66. require 5.003;
  67. use strict;
  68. package apxs;
  69.  
  70. ##
  71. ##  Configuration
  72. ##
  73.  
  74. my $CFG_TARGET        = q(httpd);            # substituted via Makefile.tmpl 
  75. my $CFG_CC            = q(m68k-unknown-amigaos-gcc);                # substituted via Makefile.tmpl
  76. my $CFG_CFLAGS        = q(-mstackextend -O3 -Dfork=vfork -m68060 -resident32 -mstackextend -Dfork=vfork -DUSE_EXPAT -I../lib/expat-lite -DNO_DL_NEEDED `../apaci`);            # substituted via Makefile.tmpl
  77. my $CFG_CFLAGS_SHLIB  = q();      # substituted via Makefile.tmpl
  78. my $CFG_LD_SHLIB      = q();          # substituted via Makefile.tmpl
  79. my $CFG_LDFLAGS_SHLIB = q(); # substituted via Makefile.tmpl 
  80. my $CFG_LIBS_SHLIB    = q();        # substituted via Makefile.tmpl 
  81. my $CFG_PREFIX        = q(/Apache);            # substituted via APACI install
  82. my $CFG_SBINDIR       = q(/Apache/bin);           # substituted via APACI install
  83. my $CFG_INCLUDEDIR    = q(/Apache/include/apache);        # substituted via APACI install
  84. my $CFG_LIBEXECDIR    = q(/Apache/libexec);        # substituted via APACI install
  85. my $CFG_SYSCONFDIR    = q(/Apache/conf);        # substituted via APACI install
  86.  
  87. ##
  88. ##  Cleanup the above stuff
  89. ##
  90. $CFG_CFLAGS =~ s|^\s+||;
  91. $CFG_CFLAGS =~ s|\s+$||;
  92. $CFG_CFLAGS =~ s|\s+`.+apaci`||;
  93.  
  94. ##
  95. ##  parse argument line
  96. ##
  97.  
  98. #   defaults for parameters
  99. my $opt_n = '';
  100. my $opt_g = '';
  101. my $opt_c = 0;
  102. my $opt_o = '';
  103. my @opt_D = ();
  104. my @opt_I = ();
  105. my @opt_L = ();
  106. my @opt_l = ();
  107. my @opt_W = ();
  108. my @opt_S = ();
  109. my $opt_e = 0;
  110. my $opt_i = 0;
  111. my $opt_a = 0;
  112. my $opt_A = 0;
  113. my $opt_q = 0;
  114.  
  115. #   this subroutine is derived from Perl's getopts.pl with the enhancement of
  116. #   the "+" metacharater at the format string to allow a list to be build by
  117. #   subsequent occurance of the same option.
  118. sub Getopts {
  119.     my ($argumentative, @ARGV) = @_;
  120.     my (@args, $first, $rest, $pos);
  121.     my ($errs) = 0;
  122.     local ($_);
  123.     local ($[) = 0;
  124.  
  125.     @args = split( / */, $argumentative);
  126.     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
  127.         ($first, $rest) = ($1,$2);
  128.         if ($_ =~ m|^--$|) {
  129.             shift(@ARGV);
  130.             last;
  131.         }
  132.         $pos = index($argumentative,$first);
  133.         if ($pos >= $[) {
  134.             if ($args[$pos+1] eq ':') {
  135.                 shift(@ARGV);
  136.                 if ($rest eq '') {
  137.                     unless (@ARGV) {
  138.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  139.                         ++$errs;
  140.                     }
  141.                     $rest = shift(@ARGV);
  142.                 }
  143.                 eval "\$opt_$first = \$rest;";
  144.             }
  145.             elsif ($args[$pos+1] eq '+') {
  146.                 shift(@ARGV);
  147.                 if ($rest eq '') {
  148.                     unless (@ARGV) {
  149.                         print STDERR "apxs:Error: Incomplete option: $first (needs an argument)\n";
  150.                         ++$errs;
  151.                     }
  152.                     $rest = shift(@ARGV);
  153.                 }
  154.                 eval "push(\@opt_$first, \$rest);";
  155.             }
  156.             else {
  157.                 eval "\$opt_$first = 1";
  158.                 if ($rest eq '') {
  159.                     shift(@ARGV);
  160.                 }
  161.                 else {
  162.                     $ARGV[0] = "-$rest";
  163.                 }
  164.             }
  165.         }
  166.         else {
  167.             print STDERR "apxs:Error: Unknown option: $first\n";
  168.             ++$errs;
  169.             if ($rest ne '') {
  170.                 $ARGV[0] = "-$rest";
  171.             }
  172.             else {
  173.                 shift(@ARGV);
  174.             }
  175.         }
  176.     }
  177.     return ($errs == 0, @ARGV);
  178. }
  179.  
  180. sub usage {
  181.     print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
  182.     print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
  183.     print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]\n";
  184.     print STDERR "               [-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]\n";
  185.     print STDERR "               [-Wl,<flags>] <files> ...\n";
  186.     print STDERR "       apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  187.     print STDERR "       apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> ...\n";
  188.     exit(1);
  189. }
  190.  
  191. #   option handling
  192. my $rc;
  193. ($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaA", @ARGV);
  194. &usage if ($rc == 0);
  195. &usage if ($#ARGV == -1 and not $opt_g);
  196. &usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and not $opt_c and not $opt_e);
  197.  
  198. #   argument handling
  199. my @args = @ARGV;
  200. my $name = 'unknown';
  201. $name = $opt_n if ($opt_n ne '');
  202.  
  203. #   overriding of configuration variables
  204. if (@opt_S) {
  205.     my ($opt_S);
  206.     foreach $opt_S (@opt_S) {
  207.         if ($opt_S =~ m/^([^=]+)=(.*)$/) {
  208.             my ($var, $val) = ($1, $2);
  209.             my $oldval = eval "\$CFG_$var";
  210.             unless ($var and $oldval) {
  211.                 print STDERR "apxs:Error: no config variable $var\n";
  212.                 &usage;
  213.             }
  214.             eval "\$CFG_${var}=\"${val}\"";
  215.         } else {
  216.             print STDERR "apxs:Error: malformatted -S option\n";
  217.             &usage;
  218.         }       
  219.     }
  220. }
  221.  
  222. ##
  223. ##  Initial DSO support check
  224. ##
  225. if ($^O ne "MSWin32") {
  226. if (not -x "$CFG_SBINDIR/$CFG_TARGET") {
  227.     print STDERR "apxs:Error: $CFG_SBINDIR/$CFG_TARGET not found or not executable\n";
  228.     exit(1);
  229. }
  230. if (not grep(/mod_so/, `$CFG_SBINDIR/$CFG_TARGET -l`)) {
  231.     print STDERR "apxs:Error: Sorry, no DSO support for Apache available\n";
  232.     print STDERR "apxs:Error: under your platform. Make sure the Apache\n";
  233.     print STDERR "apxs:Error: module mod_so is compiled into your server\n";
  234.     print STDERR "apxs:Error: binary `$CFG_SBINDIR/$CFG_TARGET'.\n";
  235.     exit(1);
  236. }
  237. }
  238.  
  239. ##
  240. ##  Operation
  241. ##
  242.  
  243. #   helper function for executing a list of
  244. #   system command with return code checks
  245. sub execute_cmds {
  246.     my (@cmds) = @_;
  247.     my ($cmd, $rc);
  248.  
  249.     foreach $cmd (@cmds) {
  250.         print STDERR "$cmd\n";
  251.         $rc = system("$cmd");
  252.         if ($rc != 0) {
  253.             printf(STDERR "apxs:Break: Command failed with rc=%d\n", $rc >> 8);
  254.             exit(1);
  255.         }
  256.     }
  257. }
  258.  
  259. if ($opt_g) {
  260.     ##
  261.     ##  SAMPLE MODULE SOURCE GENERATION
  262.     ##
  263.  
  264.     if (-d $name) {
  265.         print STDERR "apxs:Error: Directory `$name' already exists. Remove it first\n";
  266.         exit(1);
  267.     }
  268.  
  269.     my $data = join('', <DATA>);
  270.     $data =~ s|%NAME%|$name|sg;
  271.     $data =~ s|%TARGET%|$CFG_TARGET|sg;
  272.  
  273.     my ($mkf, $src) = ($data =~ m|^(.+)-=#=-\n(.+)|s);
  274.  
  275.     print STDERR "Creating [DIR]  $name\n";
  276.     system("mkdir $name");
  277.     print STDERR "Creating [FILE] $name/Makefile\n";
  278.     open(FP, ">${name}/Makefile") || die;
  279.     print FP $mkf;
  280.     close(FP);
  281.     print STDERR "Creating [FILE] $name/mod_$name.c\n";
  282.     open(FP, ">${name}/mod_${name}.c") || die;
  283.     print FP $src;
  284.     close(FP);
  285.  
  286.     exit(0);
  287. }
  288.  
  289. if ($opt_q) {
  290.     ##
  291.     ##  QUERY INFORMATION 
  292.     ##
  293.  
  294.     my $result = '';
  295.     my $arg;
  296.     foreach $arg (@args) {
  297.         my $ok = 0;
  298.         my $name;
  299.         foreach $name (qw(
  300.             TARGET CC CFLAGS CFLAGS_SHLIB LD_SHLIB LDFLAGS_SHLIB LIBS_SHLIB
  301.             PREFIX SBINDIR INCLUDEDIR LIBEXECDIR SYSCONFDIR
  302.         )) {
  303.             if ($arg eq $name or $arg eq lc($name)) {
  304.                 my $val = eval "\$CFG_$name";
  305.                 $result .= "${val}##";
  306.                 $ok = 1;
  307.             }
  308.         }
  309.         if (not $ok) {
  310.             printf(STDERR "apxs:Error: Invalid query string `%s'\n", $arg);
  311.             exit(1);
  312.         }
  313.     }
  314.     $result =~ s|##$||;
  315.     $result =~ s|##| |g;
  316.     print $result;
  317. }
  318.  
  319. if ($opt_c) {
  320.     ##
  321.     ##  DSO COMPILATION
  322.     ##
  323.  
  324.     #   split files into sources and objects
  325.     my @srcs = ();
  326.     my @objs = ();
  327.     my $f;
  328.     foreach $f (@args) {
  329.         if ($f =~ m|\.c$|) {
  330.             push(@srcs, $f);
  331.         }
  332.         else {
  333.             push(@objs, $f);
  334.         }
  335.     }
  336.  
  337.     #   determine output file
  338.     my $dso_file;
  339.     if ($opt_o eq '') {
  340.         if ($#srcs > -1) {
  341.             $dso_file = $srcs[0];
  342.             $dso_file =~ s|\.[^.]+$|.so|;
  343.         }
  344.         elsif ($#objs > -1) {
  345.             $dso_file = $objs[0];
  346.             $dso_file =~ s|\.[^.]+$|.so|;
  347.         }
  348.         else {
  349.             $dso_file = "mod_unknown.so";
  350.         }
  351.     }
  352.     else {
  353.         $dso_file = $opt_o;
  354.     }
  355.  
  356.     #   create compilation commands
  357.     my @cmds = ();
  358.     my $opt = '';
  359.     my ($opt_Wc, $opt_I, $opt_D);
  360.     foreach $opt_Wc (@opt_W) {
  361.         $opt .= "$1 " if ($opt_Wc =~ m|^\s*c,(.*)$|);
  362.     }
  363.     foreach $opt_I (@opt_I) {
  364.         $opt_I = '"' . $opt_I . '"' if ($opt_I =~ m|\s|);
  365.         $opt .= "-I$opt_I ";
  366.     }
  367.     foreach $opt_D (@opt_D) {
  368.         $opt .= "-D$opt_D ";
  369.     }
  370.     my $cflags = "$CFG_CFLAGS $CFG_CFLAGS_SHLIB";
  371.     if ($^O eq "MSWin32") {
  372.         my $d = $dso_file;
  373.         $d =~ s|\.so$||;
  374.         $d = '"' . $d . '"' if ($d =~ m|\s|);
  375.         $opt .= "-Fd$d ";
  376.     }
  377.     my $s;
  378.     foreach $s (@srcs) {
  379.         my $o = $s;
  380.         $s = '"' . $s . '"' if ($s =~ m|\s|);
  381.         if ($^O ne "MSWin32") {
  382.             $o =~ s|\.c$|.o|;
  383.             $o =~ s|^.*/||;
  384.             $o = '"' . $o . '"' if ($o =~ m|\s|);
  385.             push(@cmds, "$CFG_CC $cflags -I$CFG_INCLUDEDIR $opt -c $s");
  386.         } else {
  387.             $o =~ s|\.c$|.obj|;
  388.             $o =~ s|^.*/||;
  389.             $o = '"' . $o . '"' if ($o =~ m|\s|);
  390.             push(@cmds, "$CFG_CC $cflags -I\"$CFG_INCLUDEDIR\" $opt -c $s -Fo$o");
  391.         }
  392.         unshift(@objs, $o);
  393.     }
  394.  
  395.     #   create link command
  396.     my $cmd;
  397.     if ($^O ne "MSWin32") {
  398.         $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -o $dso_file";
  399.     } else {
  400.         $cmd = "$CFG_LD_SHLIB $CFG_LDFLAGS_SHLIB -out:\"$dso_file\"";
  401.     }
  402.     my $o;
  403.     foreach $o (@objs) {
  404.         $cmd .= " $o";
  405.     }
  406.     $opt = '';
  407.     my ($opt_Wl, $opt_L, $opt_l);
  408.     foreach $opt_Wl (@opt_W) {
  409.         if ($CFG_LD_SHLIB !~ m/gcc$/) {
  410.             $opt .= " $1" if ($opt_Wl =~ m|^\s*l,(.*)$|);
  411.         } else {
  412.             $opt .= " -W$opt_Wl";
  413.         }
  414.     }
  415.     foreach $opt_L (@opt_L) {
  416.         if ($^O ne "MSWin32") {
  417.             $opt .= " -L$opt_L";
  418.         } else {
  419.             $opt .= " -libpath:\"$opt_L\"";
  420.         }
  421.     }
  422.     foreach $opt_l (@opt_l) {
  423.         if ($^O ne "MSWin32") {
  424.             $opt .= " -l$opt_l";
  425.         } else {
  426.             $opt .= " $opt_l";
  427.         }
  428.     }
  429.     $cmd .= $opt;
  430.     $cmd .= " $CFG_LIBS_SHLIB";
  431.     push(@cmds, $cmd);
  432.  
  433.     #   execute the commands
  434.     &execute_cmds(@cmds);
  435.  
  436.     #   allow one-step compilation and installation
  437.     if ($opt_i or $opt_e) {
  438.         @args = ($dso_file);
  439.     }
  440. }
  441.  
  442. if ($opt_i or $opt_e) {
  443.     ##
  444.     ##  DSO INSTALLATION
  445.     ##
  446.  
  447.     #   determine installation commands
  448.     #   and corresponding LoadModule/AddModule directives
  449.     my @lmd = ();
  450.     my @amd = ();
  451.     my @cmds = ();
  452.     my $f;
  453.     foreach $f (@args) {
  454.         if ($f !~ m|\.so$|) {
  455.             print STDERR "apxs:Error: file $f is not a DSO\n";
  456.             exit(1);
  457.         }
  458.         my $t = $f;
  459.         if ($^O ne "MSWin32") {
  460.             $t =~ s|^.+/([^/]+)$|$1|;
  461.             if ($opt_i) {
  462.                 push(@cmds, "cp $f $CFG_LIBEXECDIR/$t");
  463.                 push(@cmds, "chmod 755 $CFG_LIBEXECDIR/$t");
  464.             }
  465.         }
  466.     else {
  467.             $t =~ s|^.+[/\\]([^/\\]+)$|$1|;
  468.             if ($opt_i) {
  469.                 push(@cmds, "copy \"$f\" \"$CFG_LIBEXECDIR/$t\"");
  470.             }
  471.         }
  472.         
  473.         #   determine module symbolname and filename
  474.         my $filename = '';
  475.         if ($name eq 'unknown') {
  476.             $name = '';
  477.             my $base = $f;
  478.             $base =~ s|\.[^.]+$||;
  479.             if (-f "$base.c") {
  480.                 open(FP, "<$base.c");
  481.                 my $content = join('', <FP>);
  482.                 close(FP);
  483.                 if ($content =~ m|.*module\s+(?:MODULE_VAR_EXPORT\s+)?([a-zA-Z0-9_]+)_module\s*=\s*.*|s) {
  484.                     $name = "$1";
  485.                     $filename = "$base.c";
  486.                     $filename =~ s|^.+/||;
  487.                     $filename =~ s|^.+\\|| if ($^O eq "MSWin32");
  488.                 }
  489.             }
  490.             if ($name eq '') {
  491.                 if ($base =~ m|.*mod_([a-zA-Z0-9_]+)\..+|) {
  492.                     $name = "$1";
  493.                     $filename = $base;
  494.                     $filename =~ s|^.+/||;
  495.                     $filename =~ s|^.+\\|| if ($^O eq "MSWin32");
  496.                 }
  497.             }
  498.             if ($name eq '') {
  499.                 print STDERR "apxs:Error: Sorry, cannot determine bootstrap symbol name.\n";
  500.                 print STDERR "apxs:Error: Please specify one with option `-n'.\n";
  501.                 exit(1);
  502.             }
  503.         }
  504.         if ($filename eq '') {
  505.             $filename = "mod_${name}.c";
  506.         }
  507.         my $dir = $CFG_LIBEXECDIR;
  508.         $dir =~ s|^$CFG_PREFIX/?||;
  509.         $dir =~ s|(.)$|$1/|;
  510.         push(@lmd, sprintf("LoadModule %-18s %s", "${name}_module", "$dir$t"));
  511.         push(@amd, sprintf("AddModule %s", $filename));
  512.     }
  513.  
  514.     #   activate module via LoadModule/AddModule directive
  515.     if ($opt_a or $opt_A) {
  516.         my $cfgbase = "$CFG_SYSCONFDIR/$CFG_TARGET";
  517.         if (not -f "$cfgbase.conf") {
  518.             print STDERR "apxs:Error: Config file $cfgbase.conf not found\n";
  519.             exit(1);
  520.         }
  521.  
  522.         open(FP, "<$cfgbase.conf") || die;
  523.         my $content = join('', <FP>);
  524.         close(FP);
  525.  
  526.         if ($content !~ m|\n#?\s*LoadModule\s+|) {
  527.             print STDERR "apxs:Error: Activation failed for custom $cfgbase.conf file.\n";
  528.             print STDERR "apxs:Error: At least one `LoadModule' directive already has to exist.\n";
  529.             exit(1);
  530.         }
  531.  
  532.         my $lmd;
  533.         my $c = '';
  534.         $c = '#' if ($opt_A);
  535.         foreach $lmd (@lmd) {
  536.             my $what = $opt_A ? "preparing" : "activating";
  537.             if ($content !~ m|\n#?\s*$lmd|) {
  538.                  $content =~ s|^(.*\n#?\s*LoadModule\s+[^\n]+\n)|$1$c$lmd\n|sg;
  539.             } else {
  540.                  $content =~ s|^(.*\n)#?\s*$lmd[^\n]*\n|$1$c$lmd\n|sg;
  541.             }
  542.             $lmd =~ m|LoadModule\s+(.+?)_module.*|;
  543.             print STDERR "[$what module `$1' in $cfgbase.conf]\n";
  544.         }
  545.         my $amd;
  546.         foreach $amd (@amd) {
  547.             if ($content !~ m|\n#?\s*$amd|) {
  548.                  $content =~ s|^(.*\n#?\s*AddModule\s+[^\n]+\n)|$1$c$amd\n|sg;
  549.             } else {
  550.                  $content =~ s|^(.*\n)#?\s*$amd[^\n]*\n|$1$c$amd\n|sg;
  551.             }
  552.         }
  553.         if (@lmd or @amd) {
  554.             if (open(FP, ">$cfgbase.conf.new")) {
  555.                 print FP $content;
  556.                 close(FP);
  557.                 if ($^O ne "MSWin32") {
  558.                     push(@cmds, "cp $cfgbase.conf $cfgbase.conf.bak");
  559.                     push(@cmds, "cp $cfgbase.conf.new $cfgbase.conf");
  560.                     push(@cmds, "rm $cfgbase.conf.new");
  561.                 } else {
  562.                     $cfgbase =~ s|/|\\|g;
  563.                     push(@cmds, "copy \"$cfgbase.conf\" \"$cfgbase.conf.bak\"");
  564.                     push(@cmds, "copy \"$cfgbase.conf.new\" \"$cfgbase.conf\"");
  565.                     push(@cmds, "del \"$cfgbase.conf.new\"");
  566.                 }
  567.             } else {
  568.                 print STDERR "apxs:Error: unable to open configuration file\n";
  569.             }
  570.         }
  571.     }
  572.  
  573.     #   execute the commands
  574.     &execute_cmds(@cmds);
  575. }
  576.  
  577. ##EOF##
  578. __DATA__
  579. ##
  580. ##  Makefile -- Build procedure for sample %NAME% Apache module
  581. ##  Autogenerated via ``apxs -n %NAME% -g''.
  582. ##
  583.  
  584. #   the used tools
  585. APXS=apxs
  586. APACHECTL=apachectl
  587.  
  588. #   additional user defines, includes and libraries
  589. #DEF=-Dmy_define=my_value
  590. #INC=-Imy/include/dir
  591. #LIB=-Lmy/lib/dir -lmylib
  592.  
  593. #   the default target
  594. all: mod_%NAME%.so
  595.  
  596. #   compile the DSO file
  597. mod_%NAME%.so: mod_%NAME%.c
  598.     $(APXS) -c $(DEF) $(INC) $(LIB) mod_%NAME%.c
  599.  
  600. #   install the DSO file into the Apache installation
  601. #   and activate it in the Apache configuration
  602. install: all
  603.     $(APXS) -i -a -n '%NAME%' mod_%NAME%.so
  604.  
  605. #   cleanup
  606. clean:
  607.     -rm -f mod_%NAME%.o mod_%NAME%.so
  608.  
  609. #   simple test
  610. test: reload
  611.     lynx -mime_header http://localhost/%NAME%
  612.  
  613. #   reload the module by installing and restarting Apache
  614. reload: install restart
  615.  
  616. #   the general Apache start/restart/stop procedures
  617. start:
  618.     $(APACHECTL) start
  619. restart:
  620.     $(APACHECTL) restart
  621. stop:
  622.     $(APACHECTL) stop
  623.  
  624. -=#=-
  625. /* 
  626. **  mod_%NAME%.c -- Apache sample %NAME% module
  627. **  [Autogenerated via ``apxs -n %NAME% -g'']
  628. **
  629. **  To play with this sample module, first compile it into a
  630. **  DSO file and install it into Apache's libexec directory 
  631. **  by running:
  632. **
  633. **    $ apxs -c -i mod_%NAME%.c
  634. **
  635. **  Then activate it in Apache's %TARGET%.conf file, for instance
  636. **  for the URL /%NAME%, as follows:
  637. **
  638. **    #   %TARGET%.conf
  639. **    LoadModule %NAME%_module libexec/mod_%NAME%.so
  640. **    <Location /%NAME%>
  641. **    SetHandler %NAME%
  642. **    </Location>
  643. **
  644. **  Then after restarting Apache via
  645. **
  646. **    $ apachectl restart
  647. **
  648. **  you immediately can request the URL /%NAME and watch for the
  649. **  output of this module. This can be achieved for instance via:
  650. **
  651. **    $ lynx -mime_header http://localhost/%NAME% 
  652. **
  653. **  The output should be similar to the following one:
  654. **
  655. **    HTTP/1.1 200 OK
  656. **    Date: Tue, 31 Mar 1998 14:42:22 GMT
  657. **    Server: Apache/1.3.4 (Unix)
  658. **    Connection: close
  659. **    Content-Type: text/html
  660. **  
  661. **    The sample page from mod_%NAME%.c
  662. */ 
  663.  
  664. #include "httpd.h"
  665. #include "http_config.h"
  666. #include "http_protocol.h"
  667. #include "ap_config.h"
  668.  
  669. /* The sample content handler */
  670. static int %NAME%_handler(request_rec *r)
  671. {
  672.     r->content_type = "text/html";      
  673.     ap_send_http_header(r);
  674.     if (!r->header_only)
  675.         ap_rputs("The sample page from mod_%NAME%.c\n", r);
  676.     return OK;
  677. }
  678.  
  679. /* Dispatch list of content handlers */
  680. static const handler_rec %NAME%_handlers[] = { 
  681.     { "%NAME%", %NAME%_handler }, 
  682.     { NULL, NULL }
  683. };
  684.  
  685. /* Dispatch list for API hooks */
  686. module MODULE_VAR_EXPORT %NAME%_module = {
  687.     STANDARD_MODULE_STUFF, 
  688.     NULL,                  /* module initializer                  */
  689.     NULL,                  /* create per-dir    config structures */
  690.     NULL,                  /* merge  per-dir    config structures */
  691.     NULL,                  /* create per-server config structures */
  692.     NULL,                  /* merge  per-server config structures */
  693.     NULL,                  /* table of config file commands       */
  694.     %NAME%_handlers,       /* [#8] MIME-typed-dispatched handlers */
  695.     NULL,                  /* [#1] URI to filename translation    */
  696.     NULL,                  /* [#4] validate user id from request  */
  697.     NULL,                  /* [#5] check if the user is ok _here_ */
  698.     NULL,                  /* [#3] check access by host address   */
  699.     NULL,                  /* [#6] determine MIME type            */
  700.     NULL,                  /* [#7] pre-run fixups                 */
  701.     NULL,                  /* [#9] log a transaction              */
  702.     NULL,                  /* [#2] header parser                  */
  703.     NULL,                  /* child_init                          */
  704.     NULL,                  /* child_exit                          */
  705.     NULL                   /* [#0] post read-request              */
  706. };
  707.  
  708.